package com.itheima.day09.StreamLiu;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.lang.System.out;

public class Test {
    public static void main(String[] args) {
        List<Stus> students = new ArrayList<>();
        students.add(new Stus("小王", 18, 66));
        students.add(new Stus("小张张", 17, 99));
        students.add(new Stus("小李李", 26, 20));
        students.add(new Stus("小赵", 16, 77));
        students.add(new Stus("小刘", 19, 18));
        students.add(new Stus("小李", 26, 20));
        out.println( students);
        //需求1：获取成绩记过60分的所有学生，按照成绩降序输出
        students.stream().filter(s -> s.getScore()>= 60).sorted((o1, o2) -> Double.compare(o2.getScore(), o1.getScore())).forEach(out::println);
        out.println("---------------------------");
        //需求2：获取年龄大于18小于25的学生，并升序排序
        students.stream().filter(s -> s.getAge()>18&&s.getAge()<25).sorted().forEach(out::println);
        out.println("---------------------------");
        //需求3：获取所有学生的成绩排名，取前三个，并降序排序
        students.stream().sorted((o1, o2) -> Double.compare(o1.getScore(), o2.getScore())).skip(students.size()-3).forEach(out::println);
        //需求4：过滤出未成年与不及格的学生，并将两个集合合并成一个
        out.println("---------------------------");
        Stream stream =students.stream().filter(s -> s.getAge()<= 18).map(s -> new Stus(s.getName(), s.getAge(), s.getScore()));
        Stream stream1 =students.stream().filter(s->s.getScore()<=60).map(s->new Stus(s.getName(),s.getAge(),0));
        Stream.concat(stream,stream1).forEach(out::println);
        out.println("---------------------------");
        //需求5：获取三个字的学生，统计输出数量
        long count = students.stream().filter(s ->s.getName().length()==3).count();
        out.println("三字学生名个数为："+count);
        out.println("---------------------------");
        //需求6：获取考试成绩最后一名的学生信息
        Optional<Stus> last = students.stream().min((o1, o2) -> Double.compare(o1.getScore(), o2.getScore()));
        out.println(last.get());
        out.println("---------------------------");
        //需求7：找出所有成绩不合格的学生，返回学生集合
        List list = students.stream().filter(s -> s.getScore()<60).collect(Collectors.toList());
        out.println(list);
    }
}
